﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Communication
{
    public class WashControl:ControlBase
    {
        #region 变量
        string mWashCmdDown;//放下
        string mWashCmdDown1;//放下杯口
        string mMove;
        string mWashCmdUp;//抬起
        string mInOpen = "MA", mInClose = "MW";
        string mOutOpen = "MA", mOutClose = "MW";
        //string mDrainOpen = "MA26",mDrainClose="MW26";//从洗板废液通到洗针废液的阀
        bool IsOutOpen = false;//持续吸水
        #endregion

        /// <summary>
        /// 洗板控制
        /// </summary>
        /// <param name="canID"></param>
        /// <param name="cmd"></param>
        public WashControl(short canID, string cmdDown,string cmdUp,string cmdDown1,string move,int _in,int _out)
        {
            mCanId = canID;
            mWashCmdDown = cmdDown;
            mWashCmdUp=cmdUp;
            mWashCmdDown1 = cmdDown1;
            mMove = move;
            mSCmd = new Dictionary<int, string>();
            mSCmd.Add(1, mWashCmdDown);
            mSCmd.Add(2,mWashCmdUp);
            mSCmd.Add(3, mWashCmdDown1);
            mSCmd.Add(4, mMove);

            mInOpen+=_in;
            mInClose+=_in;
            mOutOpen+=_out;
            mOutClose+=_out;
        }
        /// <summary>
        /// 放下到杯底
        /// </summary>
        /// <returns>1</returns>
        public int WashDown()
        {
            OutOpen(true);
            SendCmd(1, mWashCmdDown);
            Status = -1;
            return 1;
        }
        /// <summary>
        /// 放下到杯口
        /// </summary>
        /// <returns></returns>
        public int WashDown_1()
        {
            SendCmd(mWashCmdDown1);
            Status = -3;
            return 3;    
        }
        /// <summary>
        /// 抬起
        /// </summary>
        /// <returns></returns>
        public int WashUp()
        {
            SendCmd(2, mWashCmdUp);
            Status = -2;
            return 2;
        }
        /// <summary>
        /// 偏一点
        /// </summary>
        /// <returns></returns>
        public int MoveLittle()
        {
            SendCmd(mMove);
            Status = -4;
            return 4;
        }

        /// <summary>
        /// 进水,进水时一直吸
        /// </summary>
        public void WashIn(int inTime)
        {
            InOpen(true);
            OutOpen(true);
            Thread.Sleep(inTime);
            InOpen(false);
            Thread.Sleep(500);
            OutOpen(IsOutOpen);

        }

        /// <summary>
        /// 排水
        /// </summary>
        public void WashOut(int outTime)
        {
            OutOpen(true);
            Thread.Sleep(outTime);
            OutOpen(IsOutOpen);

        }

        public void WashOutLast()
        {
            OutOpen(true);
            Thread.Sleep(4000);
            OutOpen(IsOutOpen);
        }
        /// <summary>
        /// 进水开关
        /// </summary>
        public void InOpen(bool open)
        {
            if (open)
                Can.SendCan(Can.IO_CanID, mInOpen + Can.strEnd);
            else
                Can.SendCan(Can.IO_CanID, mInClose + Can.strEnd);
        }
        /// <summary>
        /// 排水开关
        /// </summary>
        /// <param name="open"></param>
        public void OutOpen(bool open)
        {
            if (open)
                Can.SendCan(Can.IO_CanID, mOutOpen + Can.strEnd);
            else
                Can.SendCan(Can.IO_CanID, mOutClose + Can.strEnd);
        }
        /// <summary>
        /// 洗板废液瓶通向洗针废液瓶的阀
        /// </summary>
        /// <param name="open"></param>
        public void TransportOpen(bool open)
        {
            if (open)
                Can.SendCan(Can.IO_CanID, mOutOpen + Can.strEnd);
            else
                Can.SendCan(Can.IO_CanID, mOutClose + Can.strEnd);
        }

    }
}
